/**
 * 
 */
package co.gov.medellin.sdep.sisdep.gestion.service;

import java.util.Date;
import java.util.List;

import co.gov.medellin.sdep.sisdep.gestion.exception.ArticulosConsumidosException;
import co.gov.medellin.sdep.sisdep.gestion.exception.ArticulosConsumidosRuntimeException;
import co.gov.medellin.sdep.sisdep.gestion.exception.descriptor.ArticulosConsumidosMessageDescriptor;
import co.gov.medellin.sdep.sisdep.common.message.MessageDescriptorConstant;
import co.gov.medellin.sdep.sisdep.common.service.BaseService;
import co.gov.medellin.sdep.sisdep.model.ArticulosConsumidos;
import co.gov.medellin.sdep.sisdep.model.dao.impl.IArticulosConsumidosDAOT;

/**
 * @author Usuario
 *
 */
public class ArticulosConsumidosServiceImpl extends BaseService implements IArticulosConsumidosService {

	//----------------------------------------------------------------------
	//--- propiedades y constructores                                 init()
	//----------------------------------------------------------------------

	/**
	 * default serial version
	 */
	private static final long serialVersionUID = 1L;
	/** */
	private IArticulosConsumidosDAOT articulosConsumidosDAO;

	/**
	 * 
	 */
	public ArticulosConsumidosServiceImpl() {
	}

	//----------------------------------------------------------------------
	//--- propiedades y constructores                                  end()
	//----------------------------------------------------------------------

	//----------------------------------------------------------------------
	//--- implementacion de metodos para acciones                     init()
	//----------------------------------------------------------------------

	/**
	 * 
	 */
	public void insert(ArticulosConsumidos articulosConsumidos) throws ArticulosConsumidosException {
		try{
			articulosConsumidos.setUsuarioCrea(getPrincipalUser());
			//articulosConsumidos.setFechaCrea(new Date());
			getArticulosConsumidosDAO().insert(articulosConsumidos);
		}catch (Exception e) {
			Object [] infoError = {
			};
			if(e.getCause().toString().indexOf("UNIQUE KEY") >= 0){
				throw new ArticulosConsumidosException(new ArticulosConsumidosMessageDescriptor(MessageDescriptorConstant.UK_VIOLATION), infoError, e);
			}else{
				throw new ArticulosConsumidosException(new ArticulosConsumidosMessageDescriptor(MessageDescriptorConstant.SAVE), infoError, e);
			}
		}
	}

	/**
	 * 
	 */
	public final void update(ArticulosConsumidos articulosConsumidos) throws ArticulosConsumidosException {
		try{
			articulosConsumidos.setUsuarioModifica(getPrincipalUser());			
			getArticulosConsumidosDAO().update(articulosConsumidos);
		}catch (Exception e) {
			Object [] infoError = {
			};
			if(e.getCause().toString().indexOf("UNIQUE KEY") >= 0){
				throw new ArticulosConsumidosRuntimeException(new ArticulosConsumidosMessageDescriptor(MessageDescriptorConstant.UK_VIOLATION), infoError, e);
			}else{
				throw new ArticulosConsumidosRuntimeException(new ArticulosConsumidosMessageDescriptor(MessageDescriptorConstant.UPDATE), infoError, e);
			}
		}
	}

	/**
	 * 
	 */
	public final void delete(ArticulosConsumidos articulosConsumidos) throws ArticulosConsumidosException {
		try {
			articulosConsumidos.setUsuarioModifica(getPrincipalUser());
			articulosConsumidos.setFechaModifica(new Date());
			getArticulosConsumidosDAO().delete(articulosConsumidos);
		}catch (Exception e) {
			Object [] infoError = {
			};
			throw new ArticulosConsumidosRuntimeException(new ArticulosConsumidosMessageDescriptor(MessageDescriptorConstant.DELETE), infoError, e);
		}
	}

	/**
	 * @return 
	 * 
	 */
	public final List load(int start,int max, ArticulosConsumidos articulosConsumidos) throws ArticulosConsumidosException {
		try{
			//return getArticulosConsumidosDAO().getAllArticulosConsumidosPaginated(start, max, criteria);
			return getArticulosConsumidosDAO().load();
		}catch (Exception e) {
			Object [] infoError = null;
			throw new ArticulosConsumidosRuntimeException(new ArticulosConsumidosMessageDescriptor(MessageDescriptorConstant.RETRIEVE), infoError, e);
		}
	}

	/**
	 * 
	 */
	public final ArticulosConsumidos get(long id) throws ArticulosConsumidosException {
		try{
			return getArticulosConsumidosDAO().findByPrimaryKey(id);
		}catch (Exception e) {
			Object [] infoError = {new Long(id)};
			throw new ArticulosConsumidosRuntimeException(new ArticulosConsumidosMessageDescriptor(MessageDescriptorConstant.GET), infoError, e);
		}
	}

	//----------------------------------------------------------------------
	//--- implementacion de metodos para acciones                      end()
	//----------------------------------------------------------------------

	//----------------------------------------------------------------------
	//--- getters and setters                                         init()
	//----------------------------------------------------------------------

	/**
	 * @author Usuario
	 *
	 */
	public IArticulosConsumidosDAOT getArticulosConsumidosDAO() {
		return articulosConsumidosDAO;
	}

	/**
	 * @author Usuario
	 *
	 */
	public void setArticulosConsumidosDAO(IArticulosConsumidosDAOT articulosConsumidosDAO) {
		this.articulosConsumidosDAO = articulosConsumidosDAO;
	}

	//----------------------------------------------------------------------
	//--- getters and setters                                          end()
	//----------------------------------------------------------------------

}
